local hx__yuanmou = fk.CreateSkill{
  name = "hx__yuanmou",
}

hx__yuanmou:addEffect("active", {
  anim_type = "control",
  prompt = "你可以用你的牌与牌堆顶的X张牌交换，你将因此法进入牌堆的牌标记为“谋”直到“谋”离开一名角色的手牌区（X为你的体力上限）",
  can_use = function(self, player)
    return player:usedSkillTimes(hx__yuanmou.name, Player.HistoryPhase) < 1
  end,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  on_use = function(self, room, effect)
    local player = effect.from
    local cards = room:getNCards(player.maxHp)
    local results = room:askToArrangeCards(player, {
      skill_name = hx__yuanmou.name,
      card_map = {
        "Top", cards,
        player.general, player:getCardIds("he"),
      },
      prompt = "请交换任意张你的牌和牌堆顶的牌",
      free_arrange = false,
    })
    if #results > 0 then
      room:swapCardsWithPile(player, results[1], results[2], hx__yuanmou.name, "Top")
      for _, card in ipairs(results[1]) do
        local id = Fk:getCardById(card)
        room:addCardMark(id, "@@hx__yuanmou-inhand")
      end
    end
  end,
})

hx__yuanmou:addEffect("prohibit", {
  prohibit_use = function(self, player, card)
    if not card or player:hasSkill(hx__yuanmou.name) then return false end
    local mou_cards = {}
    for _, id in ipairs(player:getCardIds("he")) do
      if Fk:getCardById(id):getMark("@@hx__yuanmou-inhand") > 0 then
        table.insert(mou_cards, Fk:getCardById(id))
      end
    end
    
    for _, mou_card in ipairs(mou_cards) do
      if card.suit == mou_card.suit then
        return true
      end
    end
    return false
  end,
  prohibit_response = function(self, player, card)
    if not card or player:hasSkill(hx__yuanmou.name) then return false end
    local mou_cards = {}
    for _, id in ipairs(player:getCardIds("he")) do
      if Fk:getCardById(id):getMark("@@hx__yuanmou-inhand") > 0 then
        table.insert(mou_cards, Fk:getCardById(id))
      end
    end
    
    for _, mou_card in ipairs(mou_cards) do
      if card.suit == mou_card.suit then
        return true
      end
    end
    return false
  end,
})
return hx__yuanmou
